﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LibNiconico.NiconicoApi.Internal;
using System.Xml.Linq;
using System.IO;

namespace LibNiconico.NiconicoApi.Videos.Comments.Message
{
    /// <summary>
    /// ニコニコ動画メッセージ送信情報
    /// </summary>
    internal sealed class NicoVideoMessageSubmitPostInfo:NicoUrlEncodedPostAble
    {
        /// <summary>
        /// メッセージサーバURL
        /// </summary>
        internal Uri Ms { get; set; }

        /// <summary>
        /// 送信メッセージ
        /// </summary>
        internal XElement Message { get; set; }



        internal NicoVideoMessageSubmitPostInfo(Uri ms, XElement message)
        {
            this.Ms = ms;
            this.Message = message;
        }

        /// <summary>
        /// URLパスとして取得
        /// </summary>
        /// <returns></returns>
        internal override string AsPath()
        {
            return Ms.LocalPath;
        }

        /// <summary>
        /// URL問い合わせ文字列として取得
        /// </summary>
        /// <returns></returns>
        internal override string AsQuery()
        {
            return "";
        }

        /// <summary>
        /// ポスト用データとして取得
        /// </summary>
        /// <returns></returns>
        internal override byte[] AsPostData()
        {
            MemoryStream stream = new MemoryStream();
            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(Message.ToString());
            }

            return stream.ToArray();
        }
    }
}
